<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>地图导航</title>
    </head>
    <style>
            *{
                margin:0;
                padding: 0;
            }
            #container{
                width: 100%;
                height: 100vh;
                background-color: white
            }

    </style>
    <body>
        <div id="container"></div>

        <script type="text/javascript">
          window._AMapSecurityConfig = {
            securityJsCode: "f96b16e7f68c7b58363eb7653f5085aa"
          }
        </script>

        <script type="text/javascript"
                src="https://webapi.amap.com/maps?v=1.4.15&key=0b1003d779c5cb4f54560065d9355893"></script>

        <script type="text/javascript">
          //地图初始化应该在地图容器div已经添加到DOM树之后
          var map = new AMap.Map("container", {
            zoom: 15,//缩放级别
            center: [108.160368,29.282944],//中心点坐标
            //121.48500,31.206309
          });

          /*
          //接收鸿蒙端发送的消息
          var hmPort
          window.addEventListener("message", function(event){
                //map.setCenter([lng, lat]); //设置地图中心点
                if(event.data == "__init_por__"){
                    hmPort = event.ports[0]
                    hmPort.postMessage(JSON.stringify({type:"connect_ok"}))
                }
          })
          */

          window.onload = function(){
                //window.swift.alert("大家好才是真的好！")
                //window.swift.receiveData("你好")
          }

          function showHtmlMsg(){
                window.swift.toast("我是一个HTML中定义的方法！")
          }


          function getLocation(lng, lat){
                //window.swift.alert(lng+" : "+lat)
                map.setZoomAndCenter(15, [lng, lat])

                map.plugin(['AMap.PlaceSearch'], function() {
                    var PlaceSearchOptions = { //设置PlaceSearch属性
                        pageSize: 4, //每页结果数,默认10
                        pageIndex: 1, //请求页码，默认1
                        extensions: "base" //返回信息详略，默认为base（基本信息）
                    };
                    var MSearch = new AMap.PlaceSearch(PlaceSearchOptions); //构造PlaceSearch类
                    AMap.event.addListener(MSearch, "complete", (result)=>{
                        //返回结果给鸿蒙端，需要调用鸿蒙端的方法
                        window.swift.receiveData(JSON.stringify(result?.poiList?.pois||[]))
                    }); //返回结果
                    MSearch.searchNearBy("医院", new AMap.LngLat(lng, lat)); //关键字查询
                });
          }

        </script>
    </body>
</html>